#include <stdio.h>
#include <string.h>

void copy() {
    // 遍历复制
    int arr[4] = {1, 2, 3, 4};
    int arr2[4];
    memcpy(arr2, arr, sizeof(int) * 4);
    for (int i = 0; i < 4; i++) {
        printf("===>拷贝后的的元素:%d\n", arr2[i]);
    }
}

void reverse() {
    // 遍历反转
    int arr[4] = {1, 2, 3, 4};
    int length = 4;
    for (int i = 0; i < length / 2; i++) {
        int tmp = arr[i];
        arr[i] = arr[length - i - 1];
        arr[length - i - 1] = tmp;
    }

    for (int i = 0; i < length; i++) {
        printf("===>反转后的的元素:%d\n", arr[i]);
    }
}

int main() {
    // copy();
    reverse();

    // 方式一：
    int arr[10];
    printf("数组的长度:%zd\n", sizeof(arr) / sizeof(arr[0]));
    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) {
        arr[i] = i + 1;
    }
    for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) {
        printf("数组的元素:%d\n", arr[i]);
    }

    int length = 5;
    int *arr2 = (int *)malloc(length * sizeof(int));
    for (int i = 0; i < 5; i++) {
        printf("===>数组的元素:%d\n", arr2[i]);
    }
    free(arr2); // 释放

    return 0;
}